{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ef8daf8d",
   "metadata": {},
   "source": [
    "## 协程异步IO(asyncio)详解\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cf97410f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "start coroutine ... name: xihaiShen\n",
      "send value: 6\n",
      "The value of function returned: xihaiShen\n",
      "Return value:  zhihuID: xihaiShen\n"
     ]
    }
   ],
   "source": [
    "def coroutine_example(name):\n",
    "    print('start coroutine ... name:', name)\n",
    "\n",
    "    while True:\n",
    "        x = yield name\n",
    "        if x is None:\n",
    "            return 'zhihuID: xihaiShen'\n",
    "        print('send value:', x)\n",
    "\n",
    "coro = coroutine_example('xihaiShen')\n",
    "next(coro)\n",
    "print('The value of function returned:', coro.send(6))\n",
    "\n",
    "try:\n",
    "    coro.send(None)\n",
    "except StopIteration as e:\n",
    "    print('Return value: ', e.value)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "env_py38",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
